package com.yourbatis.syntax;

import com.yourbatis.interpreter.Environment;

public class ReturnStatement implements Statement {
    private final Expression expression;

    public ReturnStatement(Expression expression) {
        this.expression = expression;
    }

    @Override
    public Object execute() {
        Object eval = expression.eval();
        try{
            Environment.setReturnValue(eval);
        }catch (Exception e){
            throw new RuntimeException(); // 特殊异常用于提前退出
        }
        return eval;
    }
}
